package com.apobates.jforum2.troll.nest.service;

import com.apobates.jforum2.troll.accounts.stub.vo.MemberModelVo;
import com.apobates.jforum2.troll.actionlog.stub.vo.BoardActionVo;
import com.apobates.jforum2.troll.actionlog.stub.vo.ThreadsStatsCollectVo;
import com.apobates.jforum2.troll.actionlog.stub.vo.TopicActionVo;
import com.apobates.jforum2.troll.nest.FrontFeignClientConfig;
import com.apobates.jforum2.troll.regular.ForumActionEnum;
import com.apobates.jforum2.troll.utils.core.EntityPageResult;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 话题服务客户端
 * @author xiaofanku
 * @since 20210413
 */
@FeignClient(value="TROLL-GATEWAY",
            contextId="actionLogClient",
            fallbackFactory=ActionLogClient.ActionLogFallbackFactory.class,
            configuration = FrontFeignClientConfig.class
)
@RequestMapping(value="/logs")
public interface ActionLogClient {
    //-----------------------------------MemberController
    //9:会员话题操作统计信息
    @GetMapping("/{member}/topic/stats")
    ResponseEntity<ThreadsStatsCollectVo> getTopicActionStats(@PathVariable("member") long memberId);
    
    //11:会员的话题操作统计
    @GetMapping("/{id}/topic/action/collect")
    Map<ForumActionEnum, Long> getTopicActionCollect(@PathVariable("id") long memberId);
    
    //20:社区标兵
    @GetMapping("/model/stats")
    List<MemberModelVo> getBrandMemberModel(@RequestParam(value="size", required=false, defaultValue="10") int showSize);
    
    //24:会员的操作记录|需要前端api整合话题+回复
    @GetMapping("/{id}/topic/history/{page}/{number}")
    EntityPageResult<TopicActionVo> getMemberActionHistory(@PathVariable("id") long memberId, @PathVariable("page") int page, @PathVariable("number") int pageSize);
    
    //25:会员收藏的话题|需要前端api整合话题+回复
    @GetMapping("/{id}/topic/favorite/{page}/{number}")
    EntityPageResult<TopicActionVo> getMemberFavoriteTopic(@PathVariable("id") long memberId, @PathVariable("page") int page, @PathVariable("number") int pageSize);
    
    //26:会员点赞的话题|需要前端api整合话题+回复
    @GetMapping("/{id}/topic/like/{page}/{number}")
    EntityPageResult<TopicActionVo> getMemberLickTopic(@PathVariable("id") long memberId, @PathVariable("page") int page, @PathVariable("number") int pageSize);
    //-----------------------------------BoardController
    //13:查看指定会员的版块收藏操作
    @GetMapping("/{id}/board/favorited")
    List<BoardActionVo> getMemberFavoriteBoard(@PathVariable("id")long member, @RequestParam(value="size", required=false, defaultValue="10") int showSize);
    
    //15:分页查看指定会员收藏的版块
    @GetMapping("/{id}/board/favorited/{page}/{number}")
    EntityPageResult<BoardActionVo> getMemberFavoriteBoard(@PathVariable("id") long memberId, @PathVariable("page") int page, @PathVariable("number") int pageSize);
    
    @Component
    static class ActionLogFallbackFactory implements FallbackFactory<ActionLogClientFallback> {
        @Override
        public ActionLogClientFallback create(Throwable cause) {
            return new ActionLogClientFallback();
        }
    }
    
    static class ActionLogClientFallback implements ActionLogClient{

        @Override
        public ResponseEntity<ThreadsStatsCollectVo> getTopicActionStats(long memberId) {
            return ResponseEntity.notFound().build();
        }

        @Override
        public Map<ForumActionEnum, Long> getTopicActionCollect(long memberId) {
            return Collections.emptyMap();
        }

        @Override
        public List<MemberModelVo> getBrandMemberModel(int showSize) {
            return Collections.emptyList();
        }

        @Override
        public EntityPageResult<TopicActionVo> getMemberActionHistory(long memberId, int page, int pageSize) {
            return EntityPageResult.empty(1);
        }

        @Override
        public EntityPageResult<TopicActionVo> getMemberFavoriteTopic(long memberId, int page, int pageSize) {
            return EntityPageResult.empty(1);
        }

        @Override
        public EntityPageResult<TopicActionVo> getMemberLickTopic(long memberId, int page, int pageSize) {
            return EntityPageResult.empty(1);
        }

        @Override
        public List<BoardActionVo> getMemberFavoriteBoard(long member, int showSize) {
            return Collections.emptyList();
        }

        @Override
        public EntityPageResult<BoardActionVo> getMemberFavoriteBoard(long memberId, int page, int pageSize) {
            return EntityPageResult.empty(1);
        }
        
    }
}